package ar.com.spsolutions.splibrary.services;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import ar.com.spsolutions.splibrary.book.Book;
import ar.com.spsolutions.splibrary.book.BookComment;
import ar.com.spsolutions.splibrary.book.category.Category;

public class RESTBook implements Serializable {

	private static final long serialVersionUID = 3697156333733936646L;

	private String title;

	private String isbn;

	private String publisher;

	private String description;

	private String author;

	private List<String> comments = new ArrayList<String>();

	private List<String> categories = new ArrayList<String>();

	private Integer stars;

	private Integer loanedTimes;

	public static List<RESTBook> wrapp(final List<Book> books) {
		final List<RESTBook> wrappers = new ArrayList<RESTBook>();
		for (final Book book : books) {
			wrappers.add(new RESTBook(book));
		}
		return wrappers;
	}

	public RESTBook(final Book book) {
		this.setAuthor(book.getAuthor().getName());
		this.setDescription(book.getDescription());
		this.setIsbn(book.getIsbn());
		this.setLoanedTimes(book.getLoanedTimes());
		this.setStars(book.getStars());
		this.setTitle(book.getTitle());
		this.setComments(book);
		this.setCategories(book);
	}

	private void setCategories(final Book book) {
		for (final Category category : book.getCategories()) {
			this.getCategories().add(category.getName());
		}
	}

	private void setComments(final Book book) {
		for (final BookComment comment : book.getComments()) {
			this.getComments().add(comment.getText());
		}
	}

	public String getTitle() {
		return this.title;
	}

	public void setTitle(final String title) {
		this.title = title;
	}

	public String getIsbn() {
		return this.isbn;
	}

	public void setIsbn(final String isbn) {
		this.isbn = isbn;
	}

	public String getPublisher() {
		return this.publisher;
	}

	public void setPublisher(final String publisher) {
		this.publisher = publisher;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(final String description) {
		this.description = description;
	}

	public List<String> getCategories() {
		return this.categories;
	}

	public void setCategories(final List<String> categories) {
		this.categories = categories;
	}

	public Integer getStars() {
		return this.stars;
	}

	public void setStars(final Integer stars) {
		this.stars = stars;
	}

	public Integer getLoanedTimes() {
		return this.loanedTimes;
	}

	public void setLoanedTimes(final Integer loanedTimes) {
		this.loanedTimes = loanedTimes;
	}

	public String getAuthor() {
		return this.author;
	}

	public void setAuthor(final String author) {
		this.author = author;
	}

	public List<String> getComments() {
		return this.comments;
	}

	public void setComments(final List<String> comments) {
		this.comments = comments;
	}

}
